<?php

declare(strict_types=1);

/**
 * @Author:     Frank
 * @contact     frank_hhm@163.com
 * @Date:       2023-02-07 13:21:31
 * @Last Modified time: 2023-02-07 14:10:10
 */

namespace app\common\services\user;

use frank\base\BaseService;
use app\common\dao\user\UserWaterDao;
use frank\exception\CommonException;
use app\common\enum\EnumFactory;

/**
 * 用户流水
 * Class UserWaterService
 */
class UserWaterService extends BaseService
{
    /**
     * UserWaterService constructor.
     * @param UserWaterDao $dao
     */
    public function __construct(UserWaterDao $dao)
    {
        $this->dao = $dao;
    }

    /**
     * 新增流水
     */
    public function createWater($source, $data, $describeParam)
    {
        $this->dao->save(array_merge([
            'source' => $source,
            'describe' =>vsprintf(EnumFactory::instance('user.water_source')->getItem($source)['describe'], $describeParam),
        ], $data));
    }


    public function getUserWaterListByUid($uid){
        [$page, $limit] = $this->getPageValue();
        $where['user_id'] = $uid;
        $list = $this->dao->getUserWaterList($where, $page, $limit);
        return $list;
    }
}